package com.shop.controller;

import com.shop.service.AdminService;
import com.shop.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:zyn
 * @Date:2025/9/19--13:02:20
 */
@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {
    private AdminService as=new AdminServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       String account=req.getParameter("account");
       String password=req.getParameter("password");
        Map<String,Object> login=as.login(account,password);
        if(login.get("loginAdmin") != null){
            HttpSession session=req.getSession();
            session.setAttribute("loginAdmin",login.get("loginAdmin"));
            resp.sendRedirect("getGoods.do");
        }else{
            req.setAttribute("msg",login.get("msg"));
            req.getRequestDispatcher("login.jsp").forward(req,resp);
        }
    }
}
